package com.fr.web.core;

import com.fr.base.FRContext;
import com.fr.base.Inter;
import com.fr.web.ErrorHandler;
import com.fr.web.Weblet;
import com.fr.web.cache.WebletFactory;
import com.fr.web.core.service.ADHOCReportService;
import com.fr.web.core.service.AppServerConfigService;
import com.fr.web.core.service.AppletPrintService;
import com.fr.web.core.service.AttachmentService;
import com.fr.web.core.service.ChartHtmlService;
import com.fr.web.core.service.CloseSessionService;
import com.fr.web.core.service.ClusterUtilService;
import com.fr.web.core.service.ConsoleService;
import com.fr.web.core.service.DBCommitService;
import com.fr.web.core.service.DialogService;
import com.fr.web.core.service.EditService;
import com.fr.web.core.service.EmailService;
import com.fr.web.core.service.EmbResourceService;
import com.fr.web.core.service.EnvResourceService;
import com.fr.web.core.service.ExportService;
import com.fr.web.core.service.FSService;
import com.fr.web.core.service.FlashPrintService;
import com.fr.web.core.service.FormService;
import com.fr.web.core.service.GeneralService;
import com.fr.web.core.service.LoadAcrobatReaderService;
import com.fr.web.core.service.PDFPrintService;
import com.fr.web.core.service.PageService;
import com.fr.web.core.service.PauseService;
import com.fr.web.core.service.PlatformService;
import com.fr.web.core.service.PrintPreviewService;
import com.fr.web.core.service.RegProcessorService;
import com.fr.web.core.service.RemoteDesignService;
import com.fr.web.core.service.ReportletDealWith;
import com.fr.web.core.service.ResourceService;
import com.fr.web.core.service.ScheduleService;
import com.fr.web.core.service.ServerConfigService;
import com.fr.web.core.service.ServerJSService;
import com.fr.web.core.service.ServerProcessorService;
import com.fr.web.core.service.SessionDealWith;
import com.fr.web.core.service.TestService;
import com.fr.web.core.service.ViewService;
import com.fr.web.core.service.WidgetService;
import com.fr.web.core.service.WriteService;
import java.io.PrintWriter;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ReportDispatcher
{
  private static Service[] servicesAvailable = { ResourceService.getInstance(), WidgetService.getInstance(), PageService.getInstance(), ViewService.getInstance(), PrintPreviewService.getInstance(), EditService.getInstance(), WriteService.getInstance(), FormService.getInstance(), ExportService.getInstance(), AppletPrintService.getInstance(), PDFPrintService.getInstance(), FlashPrintService.getInstance(), AttachmentService.getInstance(), DBCommitService.getInstance(), EmbResourceService.getInstance(), DialogService.getInstance(), AppServerConfigService.getInstance(), ScheduleService.getInstance(), RegProcessorService.getInstance(), ServerJSService.getInstance(), ServerConfigService.getInstance(), ServerProcessorService.getInstance(), TestService.getInstance(), ClusterUtilService.getInstance(), ConsoleService.getInstance(), EnvResourceService.getInstance(), LoadAcrobatReaderService.getInstance(), GeneralService.getInstance(), RemoteDesignService.getInstance(), EmailService.getInstance(), FSService.getInstance(), PlatformService.getInstance(), ChartHtmlService.getInstance(), CloseSessionService.getInstance(), ADHOCReportService.getInstance(), CloseSessionService.getInstance(), PauseService.getInstance() };

  public static void dealWithRequest(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse)
    throws Exception
  {
    Object localObject1;
    Object localObject2;
    if (ClusterUtilService.CheckCluster(paramHttpServletRequest, paramHttpServletResponse))
      return;
    if (!(TestService.checkOperation(paramHttpServletRequest)))
    {
      ErrorHandlerHelper.getErrorHandler().error(paramHttpServletRequest, paramHttpServletResponse, "Please restart your web server, or contact FineReport to purchase a license.");
      return;
    }
    String str1 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "op");
    if ("getSessionID".equals(str1))
    {
      SessionDealWith.responseSessionID(paramHttpServletRequest, paramHttpServletResponse);
      return;
    }
    String str2 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "sessionID");
    if ((str2 != null) && (!(SessionDealWith.hasSessionID(str2))))
    {
      SessionDealWith.writeSessionTimeout(paramHttpServletRequest, paramHttpServletResponse);
      return;
    }
    Weblet localWeblet = WebletFactory.createWebletByRequest(paramHttpServletRequest);
    if (localWeblet != null)
    {
      localObject1 = paramHttpServletRequest.getSession(false);
      if (localObject1 != null)
      {
        localObject2 = ((HttpSession)localObject1).getAttribute("fr_authority");
        if (localObject2 != null)
          FRContext.getLogger().info(Inter.getLocText("INFO-Current_Role") + ":" + localObject2);
      }
      ReportletDealWith.dealWithReportlet(paramHttpServletRequest, paramHttpServletResponse, localWeblet);
      return;
    }
    if (str2 != null)
    {
      localObject1 = SessionDealWith.getSessionIDInfor(str2);
      if (localObject1 != null)
      {
        localObject2 = WebUtils.getHTTPRequestParameter(paramHttpServletRequest, "reportXML");
        if ((localObject2 != null) && (((String)localObject2).length() > 0))
          ((SessionIDInfor)localObject1).modifyCellElementValue((String)localObject2);
      }
    }
    if (str1 == null)
      return;
    str1 = str1.toLowerCase();
    paramHttpServletRequest.setAttribute("op", str1);
    for (int i = 0; i < servicesAvailable.length; ++i)
    {
      localObject2 = servicesAvailable[i];
      if (((Service)localObject2).accept(str1))
      {
        ((Service)localObject2).process(paramHttpServletRequest, paramHttpServletResponse, str1, str2);
        return;
      }
    }
    PrintWriter localPrintWriter = WebUtils.createPrintWriter(paramHttpServletResponse);
    localPrintWriter.println("Unresolvable Operation:" + str1);
    localPrintWriter.flush();
    localPrintWriter.close();
  }
}